package com.h2cloud.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @PackageName: com.h2cloud.test
 * @ClasssName: jwtTest
 * @Author: h2cloud
 * @Date: 2021/3/10 12:23
 */
public class jwtTest {
    public static void main(String[] args) {
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.SECOND, 15);

//        // 生成令牌
//        String token = JWT.create()
//                .withClaim("username","longkai")
//                .withExpiresAt(instance.getTime())
//                .sign(Algorithm.HMAC256("woshinibaba"));
//        System.out.println(token);
//
//        Algorithm algorithm;
//        JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256("woshinibaba")).build();
//        DecodedJWT decodedJWT = jwtVerifier.verify(token);
//        System.out.println(decodedJWT.getClaim("username").asString());

        Map<String, String> map = new HashMap<>();
        map.put("username", "longkai1");
        map.put("age", "12");
        String token = JWTUtil.getToken(map);
        System.out.println(JWTUtil.getToken(token).getClaim("username").asString());

        DecimalFormat df = new DecimalFormat("0.0000");
        double num1 = Double.parseDouble(df.format(new Random().nextDouble())) * 100;
        System.out.println(num1);
        System.out.println(100 - num1);

    }

}
